/**
 * @author wangj881
 * @date 2025-01-07 17:34
 */
public class L160_3 {

    public static void main(String[] args) {

    }

    public class Solution {
        public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
            ListNode one = headA;
            ListNode two = headB;
            while (true) {
                if (one == two) {
                    return one;
                }
                one = one.next;
                two = two.next;
                if (one == null && two == null) {
                    return null;
                }
                if (one == null) {
                    one = headB;
                }
                if (two == null) {
                    two = headA;
                }
            }
        }
    }
}
